package logic;

import common.enums.AnswerEnum;
import common.interfaces.PlayInterface;
import common.types.Pair;

public class StubPlayImpl implements PlayInterface {
	
	private int currentQuestionNumber;
	private int numOfYesAnswers;
	private int numOfNoAnswers;

	@Override
	public void startGame() throws InterruptedException {
		Thread.sleep(2000);
		currentQuestionNumber = 1;
		numOfYesAnswers = 0;
		numOfNoAnswers = 0;
	}

	@Override
	public Pair<Integer, String> getNextQuestion() {
		String question = null;
		switch (currentQuestionNumber) {
		case 1:
			question = "Is your character male?";
			break;
		case 2:
			question = "Is your character has human form?";
			break;
		case 3:
			question = "Is your character bold?";
			break;
		case 4:
			question = "Is you character evil?";
			break;
		case 5:
			question = "Is your character called Nir Biran?";
			break;
		}
		return new Pair<Integer, String>(currentQuestionNumber, question);
	}

	@Override
	public void submitAnswer(Pair<Integer, AnswerEnum> answer) throws Exception {
		Thread.sleep(1000);
		if (answer.getLeft() == currentQuestionNumber) {
			currentQuestionNumber++;
			numOfYesAnswers += answer.getRight().equals(AnswerEnum.YES) ? 1 : 0;
			numOfNoAnswers += answer.getRight().equals(AnswerEnum.NO) ? 1 : 0;
		}
		if (numOfNoAnswers >= 4) {
			throw new NullPointerException("Some kind of problem in DB");
		}
	}
	
	@Override
	public boolean isGuessed() {
		return numOfYesAnswers >= 4 || currentQuestionNumber == 6;
	}
	
	@Override
	public String getGuess() {
		return "Nir Biran";
	}
	
	@Override
	public void submitActualGuess(Pair<Boolean, String> actualGuess) throws Exception {
		System.out.println("Submitted guess: " + actualGuess);
	}
	
	@Override
	public void finishGame() {}

}
